﻿<div id="createDialog" class="crudDialog">
    <form id="createForm" method="post">
        <div class="form-group">
            <label for="jobName">兼职标题</label>
            <input id="jobName" type="text" class="form-control" required="required" name="jobName" maxlength="20">
        </div>
        <div class="form-group  ">
            <label for="jobDesc">兼职描述</label>
            <input id="jobDesc" type="text" class="form-control" required="required" name="jobDesc" maxlength="100">
        </div>

        <div class="form-group  ">
            <input id="endTime" type="date" placeholder="截止时间" class="form-control" required="required" name="endTime">
        </div>
        <div class="form-group  ">
            <label for="message">联系电话</label>
            <input id="message" type="text" class="form-control" required="required" name="message" maxlength="100">
        </div>
        <div class="form-group ">
            <input id="maxPeople" type="number" placeholder="招聘人数" class="form-control" required="required"
                   name="maxPeople" maxlength="5">
        </div>
        <div class="form-group ">
            <label for="address">地址</label>
            <input id="address" type="text" class="form-control" required="required" name="address" maxlength="50">
        </div>
        <div class="form-group ">
            <input id="price" type="number" class="form-control" placeholder="工资" required="required" name="price"
                   maxlength="5">
        </div>
        <div class="form-group">
            <select id="type" name="type" style="width: 200px">
                <option value="日结">日结</option>
                <option value="时结">时结</option>
                <option value="周结">周结</option>
            </select>
        </div>
        <div class="form-group text-right dialog-buttons">
            <a class="waves-effect waves-button" href="javascript:;" onclick="createSubmit();">保存</a>
            <a class="waves-effect waves-button" href="javascript:;" onclick="createDialog.close();">取消</a>
        </div>
    </form>
</div>
<script>
    function createSubmit() {
        $.ajax({
            type: 'post',
            url: 'create',
            data: $('#createForm').serialize(),
            beforeSend: function () {
                if ($('#jobName').val() == '') {
                    $('#jobName').focus();
                    return false;
                }
                if ($('#jobDesc').val() == '') {
                    $('#jobDesc').focus();
                    return false;
                }
                if ($('#endTime').val() == '') {
                    $('#endTime').focus();
                    return false;
                }
                if ($('#message').val() == '') {
                    $('#message').focus();
                    return false;
                }
                if ($('#maxPeople').val() == '') {
                    $('#maxPeople').focus();
                    return false;
                }

                if ($('#address').val() == '') {
                    $('#address').focus();
                    return false;
                }
                if ($('#price').val() == '') {
                    $('#price').focus();
                    return false;
                }
                var phone = $('#message').val();
                if(!(/^1[34578]\d{9}$/.test(phone))){
                    $.alert("手机号码有误，请重填");
                    return false;
                }
                var number = parseInt($('#maxPeople').val());
                if (number <= 0 || number > 200) {
                    $.alert("所招人数不在规定范围");
                    return false;
                }
                var price = parseFloat($('#price').val());
                if (price <= 0 || price > 20000) {
                    $.alert("工资不在规定范围");
                    return false;
                }
            },
            success: function (result) {
                if (result.code != 0) {
                    $.confirm({
                        theme: 'dark',
                        animation: 'rotateX',
                        closeAnimation: 'rotateX',
                        title: false,
                        content: result.errMsg,
                        buttons: {
                            confirm: {
                                text: '确认',
                                btnClass: 'waves-effect waves-button waves-light'
                            }
                        }
                    });
                } else {
                    createDialog.close();
                    $table.bootstrapTable('refresh');
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.confirm({
                    theme: 'dark',
                    animation: 'rotateX',
                    closeAnimation: 'rotateX',
                    title: false,
                    content: textStatus,
                    buttons: {
                        confirm: {
                            text: '确认',
                            btnClass: 'waves-effect waves-button waves-light'
                        }
                    }
                });
            }
        });
    }
</script>